#include <bits/stdc++.h>
using namespace std;

struct node {
  int left;
  int right;
};
node a[300005];
bool cmp(node &a, node &b) {
  return a.left < b.left ||
         (a.left == b.left && a.right < b.right); // 按起点从小到大排序
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].left >> a[i].right;
  }
  sort(a + 1, a + n + 1, cmp); // 排序

  long long ans = 0;
  for (int i = 1; i <= n; i++) { // 枚举每个区间

    int temp = i;
    int lp = i + 1, rp = n; // 二分法求它后边最后一个跟它 相交的
    while (lp <= rp) {
      int mid = (lp + rp) / 2;
      if (a[i].right < a[mid].left) {
        rp = mid - 1;
      } else {
        temp = mid;
        lp = mid + 1;
      }
    }
    ans += temp - i; // 增加数量
  }
  cout << ans;
  return 0;
}